home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10857 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  56 lines

  1. Path: uuneo.neosoft.com!usenet
  2. From: Wmatthew@lan-aces.com (W. Matthews)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointer to non-static function
  5. Date: 11 Mar 1996 15:33:20 GMT
  6. Organization: LAN-ACES, Inc.
  7. Message-ID: <4i1h40$b7i@uuneo.neosoft.com>
  8. References: <4hnsfs$cp2@nntp.ucs.ubc.ca>
  9. NNTP-Posting-Host: 198.65.178.8
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12. In article <4hnsfs$cp2@nntp.ucs.ubc.ca>, jamesdf@unixg.ubc.ca (James Fairweather) says:
  13. >
  14. >I am attempting to make some code I've written more elegant by using a
  15. >pointer to a function.  Here's how I declare the pointer:
  16. >
  17. >        double (*f)(double);
  18. >
  19. >Now I'd like to make f point to one of two functions, one declared as:
  20. >
  21. >        double CFunction::Calculate(double);
  22. >
  23. >and the other as:
  24. >
  25. >        double CEquation::Calculate(double);
  26. >
  27. >Neither are static, and CEquation and CFunction are not related by
  28. >inheritance.  Nor can they be, since CEquation contains a list of
  29. >CFunctions.
  30. >
  31. >At compile time, the compiler issues an error, "cannot convert from
  32. >double (CFunction::*)(double) to double (__cdecl *)(double)" and
  33. >"cannot convert from double (CEquation::*)(double) to double (__cdecl
  34. >*)(double)".
  35. >
  36. >This looks suspiciously like a typecasting problem to me.  I'm
  37. >wondering if what I'm attempting to do is possible, and if so, how to
  38. >do it.  What is the correct way to do the typecast, if that is the
  39. >problem?  Any help is much appreciated.
  40. >
  41. >        James
  42.  
  43. What are you doing on the storage line?
  44. f = &Calculate(x) or just f = &Calculate?
  45. (Be warned neither of these may work properly-my func pntr info a little
  46. rust, say like the TITANIC)
  47. ______________________________________________
  48. |Wyatt Matthews:       Tech Support Department |
  49. |WMATTHEW@LAN-ACES.COM        -Internet-       |
  50. |WMATTHEW.MHS@LAN-ACES          -MHS-          |
  51. |LAN-ACES Tech Support      (713)890-9786      |
  52. |LAN-ACES BBS               (713)890-9790      |
  53. |LAN-ACES Fax               (713)890-9731      |
  54. |LAN-ACES Sales             (713)890-9787      |
  55. ______________________________________________
  56.